import {
  fetchIspList, fetchPayChannelList
} from '@/services/pay/PayCommon';

export default {
  namespace: 'PayCommon',

  state: {
    ispList: [],
    payChannelList: [],
  },

  effects: {
    * fetchIspList({}, {call, put}) {
      const response = yield call(fetchIspList);
      if (response.code === 0) {
        yield put({
          type: 'chgIspList',
          payload: response.data.map(d => {
            d.value = d.id;
            d.label = `${d.name}【${d.payChannel.name}】`;
            return d;
          }),
        });
      }
    },

    * fetchPayChannelList({}, {call, put}) {
      const response = yield call(fetchPayChannelList);
      if (response.code === 0) {
        yield put({
          type: 'chgPayChannelList',
          payload: response.data.map(d => {
            d.value = d.code;
            d.label = d.name;
            return d;
          }),
        });
      }
    },

  },

  reducers: {
    chgIspList(state, action) {
      return {
        ...state,
        ispList: action.payload,
      };
    },
    chgPayChannelList(state, action) {
      return {
        ...state,
        payChannelList: action.payload,
      };
    },
  },

};
